package cn.josh.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.josh.bean.Ec_article;
import cn.josh.service.Ec_articleService;
import cn.josh.servicelmpl.Ec_articleServiceImpl;
import cn.josh.utill.PagePart;

@WebServlet("/IndexServlet")
public class IndexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{		
		//从前端取得商品类型
		String type_code = request.getParameter("type_code");
		System.out.println("商品类型是：" + type_code);
		//得到搜索框的内容
		String search = request.getParameter("search"); 
		//得到多选框商品类型
		String selectType = request.getParameter("selectType");
		
		System.out.println("搜索的内容是：" + search);
		System.out.println("单选框的商品类型是：" + selectType);
		
		//读取数据库数据
		Ec_articleService ec_ar = new Ec_articleServiceImpl();
		List<Ec_article> list = ec_ar.findAll(type_code,search,selectType);
		
		list = PagePart.getPagePart(list);
		
		//将数据存放在request中 
		request.setAttribute("list", list);
		//转发到首页
		request.getRequestDispatcher("jsp/index.jsp").forward(request, response);
		
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
	
		doGet(request, response);
	}

}
